from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-26 14:02:13.468611
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 26, Feb, 2022
Time: 14:02:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2825
Nobs: 579.000 HQIC: -48.6961
Log likelihood: 6869.95 FPE: 5.45479e-22
AIC: -48.9604 Det(Omega_mle): 4.67571e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350691 0.068109 5.149 0.000
L1.Burgenland 0.107950 0.041364 2.610 0.009
L1.Kärnten -0.110738 0.021583 -5.131 0.000
L1.Niederösterreich 0.189886 0.086393 2.198 0.028
L1.Oberösterreich 0.125669 0.085348 1.472 0.141
L1.Salzburg 0.256651 0.043819 5.857 0.000
L1.Steiermark 0.036433 0.057887 0.629 0.529
L1.Tirol 0.101714 0.046703 2.178 0.029
L1.Vorarlberg -0.068369 0.041184 -1.660 0.097
L1.Wien 0.017278 0.075870 0.228 0.820
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052404 0.146730 0.357 0.721
L1.Burgenland -0.038193 0.089110 -0.429 0.668
L1.Kärnten 0.041410 0.046496 0.891 0.373
L1.Niederösterreich -0.205110 0.186119 -1.102 0.270
L1.Oberösterreich 0.461518 0.183868 2.510 0.012
L1.Salzburg 0.281946 0.094399 2.987 0.003
L1.Steiermark 0.113879 0.124706 0.913 0.361
L1.Tirol 0.304604 0.100614 3.027 0.002
L1.Vorarlberg 0.025544 0.088724 0.288 0.773
L1.Wien -0.028601 0.163447 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199095 0.034749 5.730 0.000
L1.Burgenland 0.088315 0.021103 4.185 0.000
L1.Kärnten -0.007321 0.011011 -0.665 0.506
L1.Niederösterreich 0.239021 0.044077 5.423 0.000
L1.Oberösterreich 0.161677 0.043544 3.713 0.000
L1.Salzburg 0.039664 0.022356 1.774 0.076
L1.Steiermark 0.026966 0.029533 0.913 0.361
L1.Tirol 0.081747 0.023828 3.431 0.001
L1.Vorarlberg 0.053884 0.021012 2.564 0.010
L1.Wien 0.118961 0.038708 3.073 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119328 0.034720 3.437 0.001
L1.Burgenland 0.042435 0.021086 2.012 0.044
L1.Kärnten -0.013090 0.011002 -1.190 0.234
L1.Niederösterreich 0.169813 0.044041 3.856 0.000
L1.Oberösterreich 0.337309 0.043508 7.753 0.000
L1.Salzburg 0.099837 0.022338 4.469 0.000
L1.Steiermark 0.111089 0.029509 3.765 0.000
L1.Tirol 0.090139 0.023808 3.786 0.000
L1.Vorarlberg 0.061159 0.020995 2.913 0.004
L1.Wien -0.018393 0.038676 -0.476 0.634
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124934 0.065393 1.911 0.056
L1.Burgenland -0.045278 0.039714 -1.140 0.254
L1.Kärnten -0.045403 0.020722 -2.191 0.028
L1.Niederösterreich 0.135310 0.082947 1.631 0.103
L1.Oberösterreich 0.162869 0.081944 1.988 0.047
L1.Salzburg 0.285225 0.042071 6.780 0.000
L1.Steiermark 0.057564 0.055578 1.036 0.300
L1.Tirol 0.157359 0.044841 3.509 0.000
L1.Vorarlberg 0.097299 0.039541 2.461 0.014
L1.Wien 0.073243 0.072843 1.005 0.315
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079418 0.050953 1.559 0.119
L1.Burgenland 0.024752 0.030944 0.800 0.424
L1.Kärnten 0.053521 0.016146 3.315 0.001
L1.Niederösterreich 0.188426 0.064631 2.915 0.004
L1.Oberösterreich 0.331815 0.063849 5.197 0.000
L1.Salzburg 0.033545 0.032781 1.023 0.306
L1.Steiermark 0.006235 0.043305 0.144 0.886
L1.Tirol 0.119627 0.034939 3.424 0.001
L1.Vorarlberg 0.066199 0.030810 2.149 0.032
L1.Wien 0.098141 0.056758 1.729 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171069 0.061571 2.778 0.005
L1.Burgenland 0.005133 0.037392 0.137 0.891
L1.Kärnten -0.065979 0.019511 -3.382 0.001
L1.Niederösterreich -0.107634 0.078099 -1.378 0.168
L1.Oberösterreich 0.209489 0.077155 2.715 0.007
L1.Salzburg 0.053960 0.039612 1.362 0.173
L1.Steiermark 0.247833 0.052329 4.736 0.000
L1.Tirol 0.499589 0.042220 11.833 0.000
L1.Vorarlberg 0.064292 0.037230 1.727 0.084
L1.Wien -0.074454 0.068586 -1.086 0.278
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161614 0.068298 2.366 0.018
L1.Burgenland -0.002684 0.041478 -0.065 0.948
L1.Kärnten 0.062892 0.021643 2.906 0.004
L1.Niederösterreich 0.165501 0.086632 1.910 0.056
L1.Oberösterreich -0.054759 0.085584 -0.640 0.522
L1.Salzburg 0.208161 0.043940 4.737 0.000
L1.Steiermark 0.138791 0.058047 2.391 0.017
L1.Tirol 0.055904 0.046833 1.194 0.233
L1.Vorarlberg 0.146911 0.041298 3.557 0.000
L1.Wien 0.120805 0.076079 1.588 0.112
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392006 0.040084 9.780 0.000
L1.Burgenland -0.004717 0.024343 -0.194 0.846
L1.Kärnten -0.021320 0.012702 -1.678 0.093
L1.Niederösterreich 0.199899 0.050844 3.932 0.000
L1.Oberösterreich 0.231698 0.050229 4.613 0.000
L1.Salzburg 0.036483 0.025788 1.415 0.157
L1.Steiermark -0.016439 0.034067 -0.483 0.629
L1.Tirol 0.090492 0.027486 3.292 0.001
L1.Vorarlberg 0.050757 0.024238 2.094 0.036
L1.Wien 0.043972 0.044651 0.985 0.325
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036260 0.101870 0.168260 0.137895 0.094280 0.080593 0.032570 0.208326
Kärnten 0.036260 1.000000 -0.027763 0.132122 0.048242 0.085316 0.443675 -0.067252 0.089068
Niederösterreich 0.101870 -0.027763 1.000000 0.309692 0.118419 0.269946 0.065516 0.151520 0.288113
Oberösterreich 0.168260 0.132122 0.309692 1.000000 0.212781 0.293682 0.166130 0.135262 0.234928
Salzburg 0.137895 0.048242 0.118419 0.212781 1.000000 0.122569 0.090790 0.104491 0.122550
Steiermark 0.094280 0.085316 0.269946 0.293682 0.122569 1.000000 0.134088 0.105899 0.032885
Tirol 0.080593 0.443675 0.065516 0.166130 0.090790 0.134088 1.000000 0.062632 0.150940
Vorarlberg 0.032570 -0.067252 0.151520 0.135262 0.104491 0.105899 0.062632 1.000000 -0.005290
Wien 0.208326 0.089068 0.288113 0.234928 0.122550 0.032885 0.150940 -0.005290 1.000000